package lastRites.game.networking;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import lastRites.entities.Player;
import lastRites.game.terrain.TerrainBlock;

public class NetworkPackets {
	// ///////////////////////////////////
	// Traffic, packets, responses, etc //
	// ///////////////////////////////////
	static abstract class Response {
		public boolean	response;
	}

	public static class ChatPacket {
		public String	text;

		public ChatPacket() {}

		public ChatPacket(String text) {
			if( text.length() > 50 ) {
				text = text.substring( 0, 50 );
			}
			this.text = text;
		}
	}

	public static class GameJoinPacket {
		public int	gameStateId;

		public GameJoinPacket() {}

		public GameJoinPacket(int gameStateId) {
			this.gameStateId = gameStateId;
		}
	}

	public static class GameStartPacket {
		public int	x, y;

		public GameStartPacket() {}

		public GameStartPacket(int startX, int startY) {
			x = startX;
			y = startY;
		}
	}

	public static class LoginRequest {
		public String	ipAddress, accountName, password;

		public LoginRequest() {}

		public LoginRequest(String account, String password, String ip) {
			this.accountName = account;
			this.ipAddress = ip;
			this.password = password;
		}
	}

	public static class LoginResponse extends Response {
		public LoginResponse() {}

		public LoginResponse(boolean val) {
			this.response = val;
		}
	}

	public static class SignOff {
		public String	ipAddress, account, password;

		public SignOff() {}

		public SignOff(String account, String password, String ip) {
			this.account = account;
			this.ipAddress = ip;
			this.password = password;
		}
	}

	public static class TextDisplayPacket {
		public String	text;
		// Duration, 0 = indefinite
		public int		x, y, durationInMilliseconds, passedTime = 0;

		public TextDisplayPacket() {}

		public TextDisplayPacket(String text, int xPos, int yPos, int durationInMilliseconds) {
			if( text.length() > 50 ) {
				text = text.substring( 0, 50 );
			}
			this.text = text;
			this.x = xPos;
			this.y = yPos;
			this.durationInMilliseconds = durationInMilliseconds;
		}
	}

	public static class PlayerInfoPacket {
		public Player	player;
	}

	public static class PlayerListPacket {
		public Vector<Player>	players;

		public PlayerListPacket() {}

		public PlayerListPacket(Vector<Player> players) {
			this.players = players;
		}
	}

	public static class PlayerMovementUpdate {
		public String	player;
		public float	x, y;

		public PlayerMovementUpdate() {}

		public PlayerMovementUpdate(String name, float newX, float newY) {
			this.player = name;
			this.x = newX;
			this.y = newY;
		}
	}

	public static class PlayerMovementRequest {
		public String	player;
		public float	x, y;

		public PlayerMovementRequest() {}

		public PlayerMovementRequest(String name, float newX, float newY) {
			this.player = name;
			this.x = newX;
			this.y = newY;
		}
	}

	public static class PlayerMovementResponse extends Response {
		public PlayerMovementResponse() {}

		public PlayerMovementResponse(boolean success) {
			this.response = success;
		}
	}

	public static class TilesResponse {
		public List<TerrainBlock>	tiles;
	}

	public static class TileResponse {
		public TerrainBlock	tile;
		public int			row, col;

		public TileResponse() {}

		public TileResponse(int row, int col, TerrainBlock tile) {
			this.row = row;
			this.col = col;
			this.tile = tile;
		}
	}

	public static class TilesRequest {
		public int[]	list;

		public TilesRequest(int... coords) {
			list = coords;
		}
	}

	public static class WholeMapPacket {
		public TerrainBlock[][]		dungeon;
		public ArrayList<String>	players;
	}

	public static class MapBlockPacket {
		public TerrainBlock	block;

		public MapBlockPacket() {}

		public MapBlockPacket(TerrainBlock block) {
			this.block = block;
		}
	}
}
